#############################################################################
##
## Copyright (C) 2006-2006 Mindcast Productions. All rights reserved.
##
## This file is part of the Universal SQL Navigator - UniSQLNav.
## Find more information in: http://code.google.com/p/unisqlnav/
## Contact at carlosedp@gmail.com
##
## This file may be used under the terms of the GNU General Public
## License version 2.0 as published by the Free Software Foundation
## and appearing in the file LICENSE.GPL included in the packaging of
## this file.  Please review the following information to ensure GNU
## General Public Licensing requirements will be met:
## http://www.gnu.org/licenses/gpl.txt
##
## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
##
## $Rev: 144 $
## $Date: 2007-01-02 15:12:29 -0200 (ter, 02 jan 2007) $
##
#############################################################################

from PyQt4 import QtCore, QtGui

def makeMenuAction(widget, text, function, shortcut=None, icon=None):
    """
    Creates a popup menu action for *widget with the *text and *icon
    The action executes the passed *function
    The optional *shortcut string can be passed so a shortcut is set.
    """
    widget.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
    if icon:
        act = QtGui.QAction(icon, text, widget)
    else:
        act = QtGui.QAction(text, widget)
    act.connect(act, QtCore.SIGNAL("triggered()"), function)
    if shortcut:
        act.setShortcut(shortcut)
    widget.addAction(act)
    #return widget
